<template>
  <div>
    <div class="shang">
      <div class="gou" @click="gouwu()">购物车</div>
      <div class="shang1"><span>商品列表</span></div>
    </div>
    <div class="xiao1">
      <ul class="xiao2">
        <div v-for="(item, index) in arr" :key="index">
          <router-link
            to="/"
            active-class="active"
            @click.native="dianji(index)"
            :class="{ opq: num == index }"
            >{{ item }}</router-link
          >
        </div>
      </ul>
    </div>
    <div class="xyu">
      <div
        v-for="(item, index) in ik"
        :key="index"
        class="nia"
        :style="{ color: num1 == index ? '#8564CA' : 'black' }"
        @click="dijia(index)"
      >
        {{ item }}
      </div>
    </div>
    <div class="fool">
      <div class="diyi" v-for="(item, index) in io" :key="index">
        <div class="img2">
          <img :src="item.img" />
        </div>
        <div class="zhongj">
          <div>{{ item.name }}</div>
          <div>
            ￥<span>{{ item.price }}</span>
          </div>
          <div class="ni">
            <span>{{ item.num }}</span
            >人付款
          </div>
        </div>
        <div class="anniu" @click="diop(item)"><span>+</span></div>
      </div>
    </div>
  </div>
</template>

<script>
import { computed, defineComponent, watch } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
export default defineComponent({
  name: "Top",
  setup() {
    let store = useStore();
    let router = useRouter();
    let arr = computed(() => store.state.arr);
    let ik = computed(() => store.state.ik);
    let io = computed(() => store.state.io);
    let num = computed(() => store.state.num);
    let num1 = computed(() => store.state.num1);
    watch(io, () => {}, { immediate: true });
    // 点击跳转路由
    function gouwu() {
      router.push("/gou");
    }
    // 母婴的点击
    function dianji(v) {
      store.commit("dianji", v);
    }
    // 点击销量优先
    function dijia(n) {
      store.commit("dijia", n);
    }
    // 点击加号
    function diop(y) {
      store.commit("diop", y);
    }
    // 异步请求
    store.dispatch("ijs");
    return {
      arr,
      ik,
      dianji,
      io,
      num,
      num1,
      dijia,
      diop,
      gouwu,
    };
  },
});
</script>

<style scoped>
.shang {
  width: 100%;
  height: 0.45rem;
  line-height: 0.45rem;
  background: white;
}
.gou {
  color: black;
  float: left;
  margin-left: 0.4rem;
}
.shang1 {
  text-align: center;
  color: black;
}
.shang1 > span {
  text-align: center;
  margin-left: -0.65rem;
}
.xiao1 {
  width: 100%;
  height: 0.6rem;
  /* height: 2.933333rem; */
  background: #5d4285;
  overflow: hidden;
}
.opq {
  background-color: #9a51ff !important;
}
.xiao2 {
  display: flex;
  line-height: 0.6rem;
  text-align: center;
  white-space: nowrap;
  overflow-x: scroll;
  background-color: #5d4285;
}
.xiao2 > a {
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  padding-left: 0.24rem;
  padding-right: 0.24rem;
  text-decoration: none;
  color: white;
}
.xiao2 > div > a {
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  padding-left: 0.24rem;
  padding-right: 0.24rem;
  text-decoration: none;
  color: white;
}
/* .xiao2>a:nth-child(1){
          background: #9A51FF;
      } */
::-webkit-scrollbar {
  width: 12px;
}
.zong {
  width: 100%;
  height: 2.366667rem;
  background: white;
  display: flex;
  justify-content: center;
  align-self: center;
}
.zong > div {
  line-height: 2.366667rem;
  flex: 1;
  background: white;
  color: #878a92;
  text-align: center;
  font-size: 0.796667rem;
}
/* 下面 */
.nia {
  width: 1.25rem;
  height: 0.4rem;
  float: left;
  font-size: 0.14rem;
  line-height: 0.4rem;
  background: white;
  margin-bottom: 10px;
}
.fool {
  width: 100%;
  clear: both;
  /* background: red; */
}
.nia {
  width: 1.24rem;
  height: 0.4rem;
  background: white;
  text-align: center;
}
.xyu {
  width: 100%;
  background: white;
}
.anniu {
  float: right;
  margin-right: 20px;
  width: 0.32rem;
  height: 0.22rem;
  background: #7a46e5;
  margin-top: -0.25rem;
  border-bottom-left-radius: 1rem;
  border-top-left-radius: 1rem;
  border-bottom-right-radius: 1rem;
  border-top-right-radius: 1rem;
  color: white;
  text-align: center;
}
.diyi {
  padding: 0.1rem 0.06rem;
  height: 0.75rem;
  background: white;
  margin-top: 0.1rem;
}
.img2 {
  float: left;
  width: 0.74rem;
  height: 100%;
}
img {
  width: 0.58rem;
  width: 0.58rem;
  float: left;
  margin-left: 0.12rem;
}
.zhongj {
  float: left;
}
.zhongj > div:nth-child(1) {
  overflow: hidden;

  text-overflow: ellipsis;

  display: -webkit-box;

  -webkit-box-orient: vertical;
  line-height: 0.2rem;
  -webkit-line-clamp: 2;
  width: 2.32rem;
  height: 0.38rem;
  font-size: 0.14rem;
  color: black;
  margin-left: 0.2rem;
}
.zhongj > div:nth-child(2) {
  margin-top: 0.07rem;
  font-size: 0.15rem;
  color: #7a46e5;
  margin-left: 0.2rem;
}
.zhongj > div:nth-child(3) {
  margin-top: 0.01rem;
  font-size: 0.12rem;
  color: #a9a9a9;
  margin-left: 0.2rem;
}
</style>
